using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VAMSETUP
    {
        public DataRow Convert2AMSETUP(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryAMSETUP(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["ASMANDANT"] = " ".PadRight(2 ); 
         dwReturn["ASSETUPTAB"] = " ".PadRight(4 ); 
         dwReturn["ASSETQF"] = " ".PadRight(2 ); 
         dwReturn["ASRULENB"] = " ".PadRight(0 ); 
         dwReturn["ASSGROUP"] = " ".PadRight(2 ); 
         dwReturn["ASNEUB"] = " ".PadRight(8 ); 
         dwReturn["ASNEUD"] = " ".PadRight(0 ); 
         dwReturn["ASAENB"] = " ".PadRight(8 ); 
         dwReturn["ASAEND"] = " ".PadRight(0 ); 
         dwReturn["ASAENZL"] = " ".PadRight(0 ); 
         dwReturn["ASFVAL1"] = " ".PadRight(16 ); 
         dwReturn["ASFVAL2"] = " ".PadRight(16 ); 
         dwReturn["ASTVAL1"] = " ".PadRight(16 ); 
         dwReturn["ASTVAL2"] = " ".PadRight(16 ); 
         dwReturn["ASDNVP"] = " ".PadRight(0 ); 
         dwReturn["ASDNVM"] = " ".PadRight(0 ); 
         dwReturn["ASDNVPC"] = " ".PadRight(1 ); 
         dwReturn["ASMAXST"] = " ".PadRight(0 ); 
         dwReturn["ASSETUPTI"] = " ".PadRight(0 ); 
         dwReturn["ASSETUPTS"] = " ".PadRight(0 ); 
         dwReturn["ASCODE"] = " ".PadRight(3 ); 
         dwReturn["ASMACHRU"] = " ".PadRight(1 ); 
         dwReturn["ASGRPCHA"] = " ".PadRight(1 ); 
         dwReturn["ASTOPCHA"] = " ".PadRight(2 ); 
         dwReturn["ASHARCHA"] = " ".PadRight(1 ); 
         dwReturn["ASREDSETT"] = " ".PadRight(0 ); 
         dwReturn["ASCOSTS"] = " ".PadRight(0 ); 
         dwReturn["ASBASICTI"] = " ".PadRight(1 ); 
         dwReturn["ASPROG"] = " ".PadRight(16 ); 
         dwReturn["ASMOD"] = " ".PadRight(3 ); 
         dwReturn["ASSETTING"] = " ".PadRight(3 ); 
         dwReturn["ASFILLER"] = " ".PadRight(36 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapAMSETUP(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveAMSETUP(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryAMSETUP(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapAMSETUP(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertAMSETUP(dwLocal, ITXDBVERSION);
            }
            UpdateAMSETUP(dwLocal);
        }
        public void InsertAMSETUP(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO AMSETUP(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryAMSETUP(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM AMSETUP WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM AMSETUP  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "AMSETUP";
            Return = Result;
            return Return;
        }
        public void DeleteAMSETUP(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM AMSETUP   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateAMSETUP(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE AMSETUP SET "
                    +"ASMANDANT= :ASMANDANT,"
                    +"ASSETUPTAB= :ASSETUPTAB,"
                    +"ASSETQF= :ASSETQF,"
                    +"ASRULENB= :ASRULENB,"
                    +"ASSGROUP= :ASSGROUP,"
                    +"ASNEUB= :ASNEUB,"
                    +"ASNEUD= :ASNEUD,"
                    +"ASAENB= :ASAENB,"
                    +"ASAEND= :ASAEND,"
                    +"ASAENZL= :ASAENZL,"
                    +"ASFVAL1= :ASFVAL1,"
                    +"ASFVAL2= :ASFVAL2,"
                    +"ASTVAL1= :ASTVAL1,"
                    +"ASTVAL2= :ASTVAL2,"
                    +"ASDNVP= :ASDNVP,"
                    +"ASDNVM= :ASDNVM,"
                    +"ASDNVPC= :ASDNVPC,"
                    +"ASMAXST= :ASMAXST,"
                    +"ASSETUPTI= :ASSETUPTI,"
                    +"ASSETUPTS= :ASSETUPTS,"
                    +"ASCODE= :ASCODE,"
                    +"ASMACHRU= :ASMACHRU,"
                    +"ASGRPCHA= :ASGRPCHA,"
                    +"ASTOPCHA= :ASTOPCHA,"
                    +"ASHARCHA= :ASHARCHA,"
                    +"ASREDSETT= :ASREDSETT,"
                    +"ASCOSTS= :ASCOSTS,"
                    +"ASBASICTI= :ASBASICTI,"
                    +"ASPROG= :ASPROG,"
                    +"ASMOD= :ASMOD,"
                    +"ASSETTING= :ASSETTING,"
                    +"ASFILLER= :ASFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("ASMANDANT", OracleType.NVarChar).Value = dwData["ASMANDANT"].ToString(); 
          or1.Parameters.Add("ASSETUPTAB", OracleType.NVarChar).Value = dwData["ASSETUPTAB"].ToString(); 
          or1.Parameters.Add("ASSETQF", OracleType.NVarChar).Value = dwData["ASSETQF"].ToString(); 
          or1.Parameters.Add("ASRULENB", OracleType.NVarChar).Value = dwData["ASRULENB"].ToString(); 
          or1.Parameters.Add("ASSGROUP", OracleType.NVarChar).Value = dwData["ASSGROUP"].ToString(); 
          or1.Parameters.Add("ASNEUB", OracleType.NVarChar).Value = dwData["ASNEUB"].ToString(); 
          or1.Parameters.Add("ASNEUD", OracleType.NVarChar).Value = dwData["ASNEUD"].ToString(); 
          or1.Parameters.Add("ASAENB", OracleType.NVarChar).Value = dwData["ASAENB"].ToString(); 
          or1.Parameters.Add("ASAEND", OracleType.NVarChar).Value = dwData["ASAEND"].ToString(); 
          or1.Parameters.Add("ASAENZL", OracleType.NVarChar).Value = dwData["ASAENZL"].ToString(); 
          or1.Parameters.Add("ASFVAL1", OracleType.NVarChar).Value = dwData["ASFVAL1"].ToString(); 
          or1.Parameters.Add("ASFVAL2", OracleType.NVarChar).Value = dwData["ASFVAL2"].ToString(); 
          or1.Parameters.Add("ASTVAL1", OracleType.NVarChar).Value = dwData["ASTVAL1"].ToString(); 
          or1.Parameters.Add("ASTVAL2", OracleType.NVarChar).Value = dwData["ASTVAL2"].ToString(); 
          or1.Parameters.Add("ASDNVP", OracleType.NVarChar).Value = dwData["ASDNVP"].ToString(); 
          or1.Parameters.Add("ASDNVM", OracleType.NVarChar).Value = dwData["ASDNVM"].ToString(); 
          or1.Parameters.Add("ASDNVPC", OracleType.NVarChar).Value = dwData["ASDNVPC"].ToString(); 
          or1.Parameters.Add("ASMAXST", OracleType.NVarChar).Value = dwData["ASMAXST"].ToString(); 
          or1.Parameters.Add("ASSETUPTI", OracleType.NVarChar).Value = dwData["ASSETUPTI"].ToString(); 
          or1.Parameters.Add("ASSETUPTS", OracleType.NVarChar).Value = dwData["ASSETUPTS"].ToString(); 
          or1.Parameters.Add("ASCODE", OracleType.NVarChar).Value = dwData["ASCODE"].ToString(); 
          or1.Parameters.Add("ASMACHRU", OracleType.NVarChar).Value = dwData["ASMACHRU"].ToString(); 
          or1.Parameters.Add("ASGRPCHA", OracleType.NVarChar).Value = dwData["ASGRPCHA"].ToString(); 
          or1.Parameters.Add("ASTOPCHA", OracleType.NVarChar).Value = dwData["ASTOPCHA"].ToString(); 
          or1.Parameters.Add("ASHARCHA", OracleType.NVarChar).Value = dwData["ASHARCHA"].ToString(); 
          or1.Parameters.Add("ASREDSETT", OracleType.NVarChar).Value = dwData["ASREDSETT"].ToString(); 
          or1.Parameters.Add("ASCOSTS", OracleType.NVarChar).Value = dwData["ASCOSTS"].ToString(); 
          or1.Parameters.Add("ASBASICTI", OracleType.NVarChar).Value = dwData["ASBASICTI"].ToString(); 
          or1.Parameters.Add("ASPROG", OracleType.NVarChar).Value = dwData["ASPROG"].ToString(); 
          or1.Parameters.Add("ASMOD", OracleType.NVarChar).Value = dwData["ASMOD"].ToString(); 
          or1.Parameters.Add("ASSETTING", OracleType.NVarChar).Value = dwData["ASSETTING"].ToString(); 
          or1.Parameters.Add("ASFILLER", OracleType.NVarChar).Value = dwData["ASFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
